<template>
    <div>
        <!--卡片-->
        <el-card class="box-card">
            <!--定义面包屑-->
            <el-breadcrumb separator=">">
                <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>客户管理</el-breadcrumb-item>
                <el-breadcrumb-item>优惠券记录</el-breadcrumb-item>
            </el-breadcrumb>
            <el-divider></el-divider>
            <!--表单的搜索框杀杀杀
                 :model="双向绑定表单的数据"
            -->
            <el-form :inline="true" :model="CouponHistoyFormData"  class="demo-form-inline">

                <el-form-item >
                    <el-input v-model="CouponHistoyFormData.name" placeholder="请输入优惠券名称"></el-input>
                </el-form-item>

                <el-form-item>
                    <el-button type="primary"@click="quere"> 查询</el-button>
                </el-form-item>
            </el-form>

            <!--数据表格-->
            <template>
                <el-table
                        :data="tableData"
                        :border="true"
                        stripe
                        style="width: 100%">
                    <el-table-column
                            prop="id"
                            label="编号"
                            width="100">
                    </el-table-column>
                    <el-table-column
                            prop="tbClient.clientName"
                            label="会员名"
                            width="120">
                    </el-table-column>
                    <el-table-column
                            prop="tbCoupon.name"
                            label="优惠券名称"
                            width="200">
                    </el-table-column>
                    <el-table-column
                            prop="couponCode"
                            label="优惠码">
                    </el-table-column>
                    <el-table-column
                            prop="getType"
                            label="获取类型"
                            :formatter="getFormat">
                    </el-table-column>
                    <el-table-column
                            prop="createTime"
                            label="获取时间">
                    </el-table-column>
                    <el-table-column
                            prop="useStatus"
                            label="使用状态"
                            :formatter="statusFormat">
                    </el-table-column>
                    <el-table-column
                            prop="useTime"
                            label="使用时间">
                    </el-table-column>
                    <el-table-column
                            prop="orderSn"
                            label="订单编号">
                    </el-table-column>
                    <el-table-column label="操作" width="120">
                        <template slot-scope="scope">
                            <el-button type="danger" icon="el-icon-delete" circle @click="deleteCouponHisTable(scope.row.id)"></el-button>
                        </template>
                    </el-table-column>
                </el-table>

                <!--                分页-->
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="currentPage"
                        :page-sizes="[5, 10, 15, 20]"
                        :page-size="pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total">
                </el-pagination>
            </template>
        </el-card>

    </div>
</template>

<script>
    export default {
        name: "CouponRecord",
        data(){
            return{
                editDialogVisible:false,
                pageSize:5,
                currentPage:1,
                tableData:[],
                CouponHistoyFormData: {},
                total:0,
                id:'',
                CouponHistoyForm:{},

            }
        },
        created() {
            this.initCouponHisTable()
        },
        methods:{
            initCouponHisTable(){
                var that = this;
                this.$http.post(`/manage/couponHistory/initcouponHistory/${this.currentPage}/${this.pageSize}`,this.CouponHistoyFormData).then(function (resp) {
                    that.tableData=resp.data.result.records;
                    that.total = resp.data.result.total;
                    console.log(resp)
                })
            },

            getFormat: function( row, column) {
                return row.getType == '1' ? "主动获取" : row.getType == '0' ? "平台赠送" : "";
            },
            statusFormat: function( row, column) {
                return row.useStatus == '1' ? "未使用" : row.useStatus == '0' ? "已使用" : "已过期";
            },

            deleteCouponHisTable(id){
                var that=this;
                this.$http.delete(`/manage/couponHistory/deleteCouponHistory/${id}`, this.CouponHistoyFormData).then(function (resp) {
                    that.initCouponHisTable();
                })
            },

            handleSizeChange(v){
                this.pageSize = v;
                this.currentPage();
            },
            //切换页码时触发该方法
            handleCurrentChange(v){
                this.currentPage = v;
                this.initCouponHisTable();
            },
            quere() {
                this.initCouponHisTable()
            },


        }

    }
</script>

<style scoped>

</style>






